Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update google_sql_database and google_sql_user to not do Read actions when instance is not active #11866

Merged
merged 12 commits into from
Oct 17, 2024

Conversation

jharshika
Copy link
Contributor

@jharshika jharshika commented Sep 28, 2024

This pull request addresses issue hashicorp/terraform-provider-google#7810. If the activation policy is not ALWAYS i.e. the instance is not active, return from the get resource method of "user" and "database". In the API layer if the activation policy is not set the ALWAYS then get resource will throw an error. To avoid breaking terraform plan, updating the getter method to avoid the error during refresh.

With these changes, terraform plan and terraform apply will succeed. If the customer try to update/delete the resource, it will still throw exception as it is not supported for inactive resources.

Release Note Template for Downstream PRs (will be copied)

sql: updated `google_sql_database` and `google_sql_user` so they don't perform Read operations if their associated `google_sql_database_instance` has `activation_policy` set to "NEVER". This avoids triggering API errors while the instance is unavailable.

Copy link

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@SarahFrench, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@modular-magician modular-magician added awaiting-approval Pull requests that need reviewer's approval to run presubmit tests service/sqladmin-infra and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Sep 28, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 2 files changed, 15 insertions(+), 5 deletions(-))
google-beta provider: Diff ( 2 files changed, 15 insertions(+), 5 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 97
Passed tests: 76
Skipped tests: 14
Affected tests: 7

Click here to see the affected service packages
  • sql

Action taken

Found 7 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccDataSourceSqlDatabase_basic
  • TestAccDataSourceSqlDatabases_basic
  • TestAccSQLDatabase_sqlDatabaseBasicExample
  • TestAccSQLDatabase_sqlDatabaseDeletionPolicyExample
  • TestAccSqlDatabaseInstance_multipleOperations
  • TestAccSqlDatabase_basic
  • TestAccSqlDatabase_update

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

$\textcolor{green}{\textsf{Tests passed during RECORDING mode:}}$
TestAccDataSourceSqlDatabase_basic[Debug log]
TestAccDataSourceSqlDatabases_basic[Debug log]
TestAccSQLDatabase_sqlDatabaseBasicExample[Debug log]
TestAccSQLDatabase_sqlDatabaseDeletionPolicyExample[Debug log]
TestAccSqlDatabaseInstance_multipleOperations[Debug log]
TestAccSqlDatabase_basic[Debug log]
TestAccSqlDatabase_update[Debug log]

$\textcolor{green}{\textsf{No issues found for passed tests after REPLAYING rerun.}}$


$\textcolor{green}{\textsf{All tests passed!}}$

View the build log or the debug log for each test

Copy link
Contributor

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jharshika, thanks for pivoting from your previous approach to solve this issue!

I believe I understand the problem and the solution in this PR is option 5 described in the linked GitHub issue:

Option 5: Check the activation_policy before refreshing

Given the existing tests all pass here it looks like this change doesn't impact provisioning google_sql_* resources. However it looks like there are no tests covering the scenario that triggers the API errors in the linked GitHub issue.

Could you please add an acceptance test that would have triggered the API error prior to your PR? I'm imagining an update test where the first step provisions a google_sql_database_instance with activation_policy="ALWAYS", a google_sql_database, and a google_sql_user resource, and then in a second step activation_policy is updated to "NEVER"? There might be a better approach that better resembles how a user might trigger this API error, but either way I think we should add a test to prove the issue is solved.

@github-actions github-actions bot requested a review from SarahFrench October 9, 2024 18:55
@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Oct 9, 2024
@jharshika
Copy link
Contributor Author

Hi @SarahFrench Added the tests and verified it locally as well to verify the functionality.

@github-actions github-actions bot requested a review from SarahFrench October 10, 2024 11:38
@modular-magician modular-magician removed the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Oct 10, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 73 insertions(+), 5 deletions(-))
google-beta provider: Diff ( 3 files changed, 73 insertions(+), 5 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 99
Passed tests: 84
Skipped tests: 15
Affected tests: 0

Click here to see the affected service packages
  • sql
#### Non-exercised tests

Tests were added that are skipped in VCR:

  • TestAccSqlUser_instanceWithActivationPolicy
    🟢 All tests passed!

View the build log

Copy link
Contributor

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test!

I ran the new code and tests from this PR in our test environment and I found a few things that needed a fix. However they're mostly to do with how the testing framework works instead of the config, so I figured I'd suggest the changes in a review. Also, I confirmed that the test fails when it's run using the code from main.

I hope it's ok but I'll go ahead and merge the suggested changes, run the tests, and we should be in a position to merge.

This includes:
- Update to allow the test's post-test destroy code to delete resources without error
- Removes checks that tried to read the user's data and triggered the "Error 400: Invalid request: Invalid request since instance is not running., invalid" API error
@github-actions github-actions bot requested a review from SarahFrench October 10, 2024 14:34
@modular-magician modular-magician added awaiting-approval Pull requests that need reviewer's approval to run presubmit tests and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Oct 10, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 3 files changed, 75 insertions(+), 5 deletions(-))
google-beta provider: Diff ( 3 files changed, 75 insertions(+), 5 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 99
Passed tests: 84
Skipped tests: 15
Affected tests: 0

Click here to see the affected service packages
  • sql
#### Non-exercised tests

Tests were added that are skipped in VCR:

  • TestAccSqlUser_instanceWithActivationPolicy
    🟢 All tests passed!

View the build log

@SarahFrench
Copy link
Contributor

For future reference by maintainers, here's a build running that acc tess with the latest code: BUILD

Copy link
Contributor

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the TestAccSqlUser_instanceWithActivationPolicy test is passing! 🎉
Just to make sure nothing is overlooked, could you add a similar test for the database resource?

mmv1/products/sql/Database.yaml Show resolved Hide resolved
@github-actions github-actions bot requested a review from SarahFrench October 17, 2024 16:41
@jharshika
Copy link
Contributor Author

Thanks @SarahFrench for the suggested code changes. Updated the unit test for both user and database.

@modular-magician modular-magician added awaiting-approval Pull requests that need reviewer's approval to run presubmit tests and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Oct 17, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 4 files changed, 139 insertions(+), 8 deletions(-))
google-beta provider: Diff ( 4 files changed, 135 insertions(+), 5 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 100
Passed tests: 84
Skipped tests: 15
Affected tests: 1

Click here to see the affected service packages
  • sql
#### Non-exercised tests

🔴 Tests were added that are skipped in VCR:

  • TestAccSqlUser_instanceWithActivationPolicy

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccSqlDatabase_instanceWithActivationPolicy

Get to know how VCR tests work

@modular-magician
Copy link
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccSqlDatabase_instanceWithActivationPolicy[Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

@SarahFrench
Copy link
Contributor

I'm just running the skipped test again to confirm everything's ok. Assuming it passes I'll approve and merge. Thank you for the additional test!

Copy link
Contributor

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test mentioned here passed, so approving & merging. Thanks for such a smooth PR process!

@SarahFrench
Copy link
Contributor

Final note on this PR for any future reference:

I've set the release note to

sql: updated google_sql_database and google_sql_user so they don't perform Read operations if their associated google_sql_database_instance has activation_policy set to "NEVER". This avoids triggering API errors while the instance is unavailable.

This PR doesn't prevent create/update/delete actions as the API error is useful in those cases. We need to skip Read when the instance isn't available, as the instance isn't queryable then. There may be Terraform configurations that are valid and contain a google_sql_database_instance with other child resources, and then activation_policy is temporarily set to "NEVER". In those cases refresh actions will trigger API errors. When the instance is returned to being available then the child resources will resume as normal.

@SarahFrench SarahFrench changed the title Update the resource getter method when instance is not active Update google_sql_database and google_sql_user to not do Read actions when instance is not active Oct 17, 2024
@SarahFrench SarahFrench merged commit fa2e68e into GoogleCloudPlatform:main Oct 17, 2024
14 checks passed
varshatumburu pushed a commit to varshatumburu/magic-modules that referenced this pull request Oct 19, 2024
BBBmau pushed a commit to BBBmau/magic-modules that referenced this pull request Oct 23, 2024
BBBmau pushed a commit to BBBmau/magic-modules that referenced this pull request Oct 24, 2024
BBBmau pushed a commit to BBBmau/magic-modules that referenced this pull request Nov 5, 2024
akshat-jindal-nit pushed a commit to akshat-jindal-nit/magic-modules that referenced this pull request Nov 18, 2024
amanMahendroo pushed a commit to amanMahendroo/magic-modules that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants